package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.dao.BookDao;
import com.example.domain.Book;
import com.example.service.IBookService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class BookServiceImpl02 extends ServiceImpl<BookDao, Book> implements IBookService {

    @Autowired
    private BookDao bookDao;

    /*@Override
    public List<Book> getAll01() {
        return bookDao.selectList(null);
    }
    @Override
    public boolean saveBook01(Book book) {
        return bookDao.insert(book) > 0;
    }

    @Override
    public boolean modify01(Book book) {
        return bookDao.updateById(book) > 0;
    }

    @Override
    @Cacheable(value="cacheSpace",key="#id")
    public boolean delete01(Integer id) {
        return bookDao.deleteById(id) > 0;
    }*/

    @Override
    public IPage<Book> getPage01(int currentPage, int pageSize) {
        IPage page = new Page(currentPage,pageSize);
        bookDao.selectPage(page,null);
        return page;
    }

    @Override
    public IPage<Book> getPage01(int currentPage, int pageSize, Book book) {
        LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper<Book>();
        lqw.like(Strings.isNotEmpty(book.getType()),Book::getType,book.getType());
        lqw.like(Strings.isNotEmpty(book.getName()),Book::getName,book.getName());
        lqw.like(Strings.isNotEmpty(book.getDesct()),Book::getDesct,book.getDesct());
        IPage page = new Page(currentPage,pageSize);
        bookDao.selectPage(page,lqw);
        return page;
    }
    /*//使用逻辑删除实现图书借阅
    public boolean takeback(Book book){
        //1、找到被删除的记录
    }*/
}
